package com.work.washer.controller;

import com.work.washer.dto.CommentReq;
import com.work.washer.dto.RepairReq;
import com.work.washer.model.Comment;
import com.work.washer.model.Repair;
import com.work.washer.service.RepairService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@Tag(name = "报修")
@RestController
@RequestMapping("/repair")
public class RepairController {

    @Autowired
    private RepairService repairService;


    @Operation(summary = "报修,只传页面的字段，其他字段会自动加")
    @PostMapping("/sendFail")
    public Boolean sendFail(@RequestBody Repair repair) {
        return repairService.sendFail(repair);
    }

    @Operation(summary = "获取报修记录,类型1全部，2个人提交的")
    @PostMapping("/getFail")
    public List<Repair> getFail(@RequestParam("type") @Schema(title = "类型1全部，2个人提交的") Integer type,
                                @RequestParam(value = "userId", required = false) Integer userId,
                                @RequestParam(value = "status",required = false) Integer status) {
        return repairService.getFail(type, userId,status);
    }

    @Operation(summary = "维修")
    @PostMapping("/repair")
    public Boolean repair(@RequestBody RepairReq repairReq) {
        return repairService.repair(repairReq);
    }


    @Operation(summary = "新增评论")
    @PostMapping("/addComment")
    public boolean addComment(CommentReq req) {
        return repairService.addComment(req.getMachineId(), req.getUserId(), req.getContent(),req.getImage());
    }

    @Operation(summary = "获取评论")
    @GetMapping("/getComment")
    public List<Comment> getComment(@RequestParam("repairId") @Schema(title = "维修记录Id") Integer repairId) {
        return repairService.getComment(repairId);
    }

}